package com.qch.es.controller;

import com.qch.es.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Author qch
 * @Date 2021/7/1
 */
@RestController
public class EsController {
    @Autowired
    private PositionService service;

    //测试范文页面
   /* @GetMapping({"/", "index"})
    public String indexPage() {
        return "index";
    }*/

    @RequestMapping("/index")
    public ModelAndView index(){
        ModelAndView view = new ModelAndView("index.html");
        return view;
    }

    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    @ResponseBody
    public List<Map<String, Object>> searchPosition(@PathVariable("keyword") String keyword, @PathVariable("pageNo") int pageNo, @PathVariable("pageSize") int pageSize) throws IOException {
        List<Map<String, Object>> list = service.searchPosExtra(keyword, pageNo, pageSize);
        System.out.println(list);
        return list;
    }

    @RequestMapping("/importAll")
    @ResponseBody
    public String importAll() {
        try {
            service.importAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }
}
